<?php
/**
 * Desc: 首页
 * Created by chengshujie@star-net.cn
 * Date: 2018/05/17 15:43
 */
namespace app\index\controller;

use app\core\Controller;

class BengBen extends Controller {

    public $redis = null;

    public function __construct() {
        parent::__construct();
        $this->redis = new \Redis();
        $this->redis->connect('127.0.0.1', 6379);
    }

    public function BengBenManage() {
        return $this->fetch();
    }

    public function ajaxGetAllRoom() {
        $keys = $this->redis->sMembers('bengben-keys');
        if (empty($keys) ) {
            $return = [
                'error' => '40001',
                'msg'   => '暂无进行中的房间'
            ];
            echo json_encode($return);
            return;
        }

        $list = [];
        foreach($keys as $v) {
            $room = $this->redis->get($v);
            $room = unserialize($room);
            $room['gameStatus'] = $room['gameStatus'] == 1 ? "空闲" : "游戏中";
            $room['roomid'] = substr($v,8);
            $room['isRand'] = $room['isRand'] == true ? "随机" : "非随机";
            $list[] = $room;
        }
        $return = [
            'error' => '0',
            'list'  => $list
        ];
        echo json_encode($return);
        return;

    }
}